<template>
  <div
    class="wechatSet"
    v-loading="loading"
    element-loading-background="rgba(255, 255, 255, 0)"
  >
    <el-form ref="form" label-width="150px" class="form">
      <el-form-item label="AppId">
        <div class="input_box">
          <el-input
            v-model="wechatInfo.appId"
            placeholder="请输入AppId"
            @change="handleappId"
          ></el-input>
        </div>
      </el-form-item>
      <el-form-item label="AppSecret">
        <div class="input_box">
          <el-input
            v-model="wechatInfo.appSecret"
            placeholder="请输入AppSecret"
            @change="handleappSecret"
          ></el-input>
        </div>
      </el-form-item>
      <el-form-item label="EncodingAESKey">
        <div class="input_box">
          <el-input
            v-model="wechatInfo.encodingAESKey"
            placeholder="请输入EncodingAESKey"
            @change="handleencodingAESKey"
          ></el-input>
        </div>
      </el-form-item>
      <el-form-item label="Token">
        <div class="input_box">
          <el-input
            v-model="wechatInfo.token"
            placeholder="请输入Token"
            @change="handletoken"
          ></el-input>
        </div>
      </el-form-item>
      <el-form-item label="网页授权">
        <div>
          <el-switch
            @change="handlesilentAuthorization"
            v-model="wechatInfo.silentAuthorization"
          >
          </el-switch>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import cfg from "@/config";
export default {
  data() {
    return {
      cfg,
      wechatInfo:{}
    };
  },
  computed: {
    ...mapGetters("status", {
      loading: "loading",
    }),
  },
  created() {
    this.getWechatInfo()
  },
  methods:{
    getWechatInfo(){
      this.$api('voteSet.getWechatVote',{
        voteId:this.$route.query.id
      }).then(res=>{
        this.wechatInfo=res
      })
    },
    handleappId(){
      this.saveApi()
    },
    handleappSecret(){
      this.saveApi()
    },
    handleencodingAESKey(){
      this.saveApi()
    },
    handletoken(){
      this.saveApi()
    },
    handlesilentAuthorization(){
      this.saveApi()
    },
    saveApi() {
      this.$api("voteSet.saveWechatVote",{
        ...this.wechatInfo,
        voteId:this.$route.query.id
      }).then((res) => {
        console.log(res);
        this.$store.commit("status/SET_URL", new Date().getTime());
        this.$message({
          message: "保存成功",
          type: "success",
          duration: 1000,
        });
      });
    },
  }
};
</script>

<style lang="scss" scoped>
.wechatSet {
  width: 820px;
  min-height: 550px;
}
</style>
